import React from 'react';
// 导入useContext hook
import { useContext } from 'react';

import contextObj from './context'

const Child1 = () => {
    //在子组件中获取父组件提供的state和修改父组件state 的方法 dispatch
    const { state, dispatch } = useContext(contextObj)
    console.log('child1-state', state);
    return (
        <div>
            child1
            <p>
                <button onClick={() => dispatch({ type: '+', payload: 1 })}>child1++</button>
                {state.count}
                <button onClick={() => dispatch({ type: '-', payload: 1 })}>child1--</button>
            </p>

        </div>
    );
}

export default Child1;
